package com.ymt.bpm.util;

/**
 * Constants for sql operators
 * @author fuzheng
 *
 */
public class Operator {
	
	public static final String OPERATOR = "operator";
	
	public static final String DQUOTE = "\"";
	public static final String QUOTEL = "(";
	public static final String QUOTER = ")";
	public static final String COMMA = ",";
	public static final String SPACE = " ";
	public static final String COLON = ":";
	public static final String UL = "_";
	
	public static final String EQUAL = "equal";
	public static final String GREATORTHAN = "greaterthan";
	public static final String LESSTHAN = "lessthan";
	public static final String GREATEREQUAL = "greaterequal";
	public static final String LESSEQUAL = "lessequal";
	public static final String NOTEQUAL = "notequal";
	public static final String CONTAINS = "contains";
	public static final String NOTCONTAINS = "notcontains";
	public static final String IN = "in";
	public static final String NOTIN = "notin";
	
	public static final String SQL_EQUAL = " = ";
	public static final String SQL_GREATORTHAN = " > ";
	public static final String SQL_LESSTHAN = " < ";
	public static final String SQL_GREATEREQUAL = " >= ";
	public static final String SQL_LESSEQUAL = " <= ";
	public static final String SQL_NOTEQUAL = " <> ";
	public static final String SQL_CONTAINS = " LIKE ";
	public static final String SQL_NOTCONTAINS = " NOT LIKE ";
	
	public static final String SQL_IN = " IN ";
	public static final String SQL_NOTIN = " NOT IN ";
	
	public static final String SQL_EXIST = " EXISTS ";
	public static final String SQL_NOTEXIST = " NOT EXISTS ";
	
	public static final String SQL_TYPE_STRING = "String";
	public static final String SQL_TYPE_NUMBER = "Number";
	public static final String SQL_TYPE_DATE = "Date";
	
	public static final String SQL_DATE_FORMAT_ZH = "yyyy-MM-dd";
	//public static final String SQL_DATE_FORMATSTR_DEFAULT = "'yyyy-MM-dd'";
	public static final String SQL_DATE_FORMAT_EN = "MM/dd/yyyy";
	public static final String SQL_DATE_FORMATSS_ZH = "yyyy-MM-dd hh24:mi:ss";
	//public static final String SQL_DATE_FORMATSTR_DEFAULT = "'yyyy-MM-dd'";
	public static final String SQL_DATE_FORMATSS_EN = "MM/dd/yyyy hh24:mi:ss";
	
	public static final String SQL_QUOTE = "'";
	public static final String SQL_QUOTEANYL = "'%";
	public static final String SQL_QUOTEANYR = "%'";
	public static final String SQL_PERSENT = "%";

	public static final String SQL_SELECT = "SELECT ";
	public static final String SQL_FROM = " FROM ";
	public static final String SQL_WHERE = " WHERE ";
	public static final String SQL_WHEREAND = " WHERE 0=0 ";
	public static final String SQL_AND = " AND ";
	public static final String SQL_OR = " OR ";
	public static final String SQL_AS = " AS ";
	
	public static final String SQL_ROWNUM = "ROW_NO";
	public static final String SQL_COUNT = "COUNT";
	public static final String SQL_ORDERBY = " ORDER BY ";
	
	public static final String SQL_F_TOCHAR = "to_char";
	public static final String SQL_F_TODATE = "to_date";
	public static final String SQL_F_LOWER = "LOWER";
	public static final String SQL_F_UPPER = "UPPER";
	
	/**
	 * get db operator by text
	 * @param operator
	 * @return
	 */
	public static String getDbOperator(String operator) {
		if (Operator.GREATORTHAN.equalsIgnoreCase(operator)) {
    		return SQL_GREATORTHAN;
    	} else if (Operator.LESSTHAN.equalsIgnoreCase(operator)) {
    		return SQL_LESSTHAN;
    	} else if (Operator.GREATEREQUAL.equalsIgnoreCase(operator)) {
    		return SQL_GREATEREQUAL;
    	} else if (Operator.LESSEQUAL.equalsIgnoreCase(operator)) {
    		return SQL_LESSEQUAL;
    	} else if (Operator.NOTEQUAL.equalsIgnoreCase(operator)) {
    		return SQL_NOTEQUAL;
    	} else if (Operator.CONTAINS.equalsIgnoreCase(operator)) {
    		return SQL_CONTAINS;
    	} else if (Operator.NOTCONTAINS.equalsIgnoreCase(operator)) {
    		return SQL_NOTCONTAINS;
    	} else if (Operator.IN.equalsIgnoreCase(operator)) {
    		return SQL_IN;
    	} else if (Operator.NOTIN.equalsIgnoreCase(operator)) {
    		return SQL_NOTIN;
    	} else {
    		return SQL_EQUAL;
    	}
	}
}
